package com.ibeeking.gmc.global.api.feign.fallback;

import com.ibeeking.found.common.entity.DatabaseTemplateDTO;
import com.ibeeking.found.common.entity.DatasourceConfigDTO;
import com.ibeeking.found.common.entity.IndustryFrontendDTO;
import com.ibeeking.gmc.global.api.feign.GlobalDatasourceFeignClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GlobalDatasourceFeignFallbackFactory implements FallbackFactory<GlobalDatasourceFeignClient> {
    @Override
    public GlobalDatasourceFeignClient create(Throwable throwable) {
        return new GlobalDatasourceFeignClient() {
            @Override
            public ResponseResult<DatasourceConfigDTO> queryTenantDatasource(Integer tenantId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询租户数据源失败。", null);
            }

            @Override
            public ResponseResult<List<IndustryFrontendDTO>> quertIndustryFrontend(String industry, String frontend) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询租户数据源失败。", Collections.emptyList());
            }

            @Override
            public ResponseResult<List<DatabaseTemplateDTO>> listTemplateByIndustry(String industry) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询模板库失败。", Collections.emptyList());
            }
        };
    }
}
